package com.cn.study.controller;

import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.client.producer.SendCallback;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.common.message.Message;

/**
 * @author mjy
 * @date 2021/12/16
 * @description
 */
public class TestSendMessage {

    public static void main(String[] args) throws Exception{
        DefaultMQProducer producer = new DefaultMQProducer("deviceGroup");
        producer.setNamesrvAddr("192.168.15.170:9876");producer.setVipChannelEnabled(false);
        producer.start();
        Message message = new Message("deviceTopic", "deviceTag", "测试消息".getBytes());
        producer.send(message, new SendCallback() {
            @Override
            public void onSuccess(SendResult sendResult) {
                System.out.println("rocketMq发送成功");
            }

            @Override
            public void onException(Throwable e) {
                System.out.println("rocketMa消息发送异常"+e);
            }
        });
    }
}
